﻿using System;
using System.Diagnostics;

namespace Slwy.FrameCore.Dependency
{
    /// <summary>
    /// 依赖注入映射描述信息
    /// </summary>
    [DebuggerDisplay("Lifetime = {Lifetime}, ServiceType = {ServiceType}, ImplementationType = {ImplementationType}")]
    public class ServiceDescriptor
    {
        /// <summary>
        /// 获取 服务实例创建工厂
        /// </summary>
        public Func<IServiceProvider, object> ImplementationFactory { get; private set; }

        /// <summary>
        /// 获取 服务实例
        /// </summary>
        public object ImplementationInstance { get; private set; }

        public ServiceDescriptor(Type serviceType, Type implementationType, LifetimeStyle lifetime)
            :this (serviceType, lifetime)
        {
            this.ImplementationType = implementationType;
        }

        public ServiceDescriptor(Type serviceType, LifetimeStyle lifetime)
        {
            this.Lifetime = lifetime;
            this.ServiceType = serviceType;
        }

        public LifetimeStyle Lifetime { get; private set; }
        public Type ServiceType { get; private set; }
        public Type ImplementationType { get; private set; }
    }
}
